<!DOCTYPE HTML>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
	<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
	<title>Hello APP</title>
	<link rel="stylesheet" type="text/css" href="../../css/aui-flex.css" />
	<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
	<link rel="stylesheet" type="text/css" href="../../css/common.css" />
	<style>
		.title-left {
			margin-right: 0.4rem;
		}

		body {
			background: #f1f1f1;
		}

		.order-list {
			padding: 1rem;
			background: #fff;
			margin-top: 0.4rem;
		}

		.order-list .order-head {
			padding-bottom: 1rem;
		}

		.order-list .order-item {
			padding: 0 0 0.75rem;
		}

		.order-list .media {
			width: 3.6rem;
		}

		.textBox {
			min-height: 4.5rem;
			padding-left: 0.5rem;
		}

		.fot-btn>div {
			width: 3.6rem;
			height: 1.4rem;
			border: 1px solid #adadad;
			border-radius: 0.8rem;
			text-align: center;
			line-height: 1.3rem;
			font-size: 0.6rem;
			color: #adadad;
		}

		.fot-btn>div.collect {
			color: #E73450;
			margin-left: 0.7rem;
			border: 1px solid #E73450;
		}

		.order-list .tag {
			margin-top: -0.1rem;
			margin-right: 0.4rem;
			display: inline-block;
			color: #FFF;
			background: #FA7D83;
			border-radius: 0.1rem;
			font-size: 0.4rem;
			padding: 0 0.15rem;
			line-height: 0.75rem;
			vertical-align: middle;
		}

		.order-list .tag.on {
			background: #FFC667;
		}

		.no-more {
			padding: 0.6rem 0;
		}
		.historyBox,
		.hotBox {
				padding: 0.75rem 0.75rem 0;
		}

		.historyTtl {
				height: 1.5rem;
				font-size: 0.6rem;
				color: #adadad;
		}

		.historyTtl .delBtn {
				padding: 0.25rem;
		}

		.historyTtl .delBtn img {
				height: 0.75rem;
		}
		.tagList {
				padding: 0.25rem 0;
				margin: 0 -0.25rem;
		}

		.tagList li {
				margin: 0.25rem;
				font-size: 0.6rem;
				background: #F4F3F2;
				line-height: 1.4rem;
				padding: 0 0.5rem;
				color: #555;
				border-radius: 0.2rem;
		}
	</style>
</head>

<body>
	<div>
		<div id="data_html"></div>
		<script type="text/x-dot-template" id="history_tpl">
				<div class="historyBox">
						<div class="historyTtl aui-flex-col aui-flex-middle aui-flex-between">
								<div>历史搜索</div>
								<div class="delBtn" tapmode onClick="delConfirm();"><img src="../../image/common/13.png" alt=""></div>
						</div>
						<ul class="tagList aui-flex-col">
								{{ for(var i in it) { }} {{ if(it[i]){ }}
								<li tapmode onClick="searchTag(this);">{{= it[i]}}</li>
								{{ } }} {{ } }}
						</ul>
				</div>
		</script>
	</div>
</body>
<script type="text/javascript" src="../../script/import.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript">
var currentSearch = '';
var historyOrder;
	apiready = function() {
		api.parseTapmode();
		firstShow();
	};
//第一屏 显示
function firstShow() {
	console.log('22')
		if ($api.getStorage('orderSerch')) {
				historyOrder = $api.getStorage('orderSerch');
				console.log(JSON.stringify(historyOrder))
		} else {
				historyOrder = [];
				console.log(JSON.stringify(historyOrder))
		}
		console.log(JSON.stringify(historyOrder))
		showHistory();
}
//删除历史记录 弹窗
function delConfirm() {
		var confirmMaskTxt = ['确认清空历史记录？', '取消', '确认删除'];        
		openConfirmMask(confirmMaskTxt, 'delHistory()');
}
//确认删除历史记录
function delHistory() {
		$$('.historyBox').remove();
		historyOrder = [];
		$api.setStorage('orderSerch', historyOrder);
}
//显示历史记录
function showHistory() {
		var tpl = $$('#history_tpl').html();
		console.log(JSON.stringify(historyOrder))
		var tempFn = doT.template(tpl);
		$$('#data_html').html(tempFn(historyOrder));
		api.parseTapmode();
}


//点击标签
function searchTag(el) {
		var _this = $$(el);
		currentSearch = _this.text();
		api.execScript({
				script: 'setVal("' + currentSearch + '");'
		});
searchFn(currentSearch);
}
//搜索事件
function searchFn(s) {
	if (!s) {
		return;
	}
	currentSearch = s;
	api.openWin({
	    name: 'search_result_win',
	    url: 'search_result_win.html',
	    pageParam: {
	        name: currentSearch
	    }
	});
	// getOrderList();
	//存搜索历史
			historyOrder.unshift(currentSearch);
			var arr = unique(historyOrder);
			$api.setStorage('orderSerch', arr);
}
	// 获取订单列表
// function getOrderList(){
// 		console.log(currentSearch)
// 		api.ajax({
// 		    url: BASE_URL_2 + 'App/Mall/orderLists',
// 		    method: 'post',
// 		    data: {
// 		        values: {
// 		            userid: getUserId(),
// 								keywords:currentSearch
// 		        }
// 		    }
// 		},function(ret, err){
// 			console.log(JSON.stringify(ret))
// 		    if (ret && ret.code == 1) {
// 					$$('.notData').addClass('aui-hide');
// 					var tpl = $$('#order-list-tpl').html();
// 					var tempFn = doT.template(tpl);
// 					$$('#order-list-html').html(tempFn(ret.data));
// 		    } else {
// 					var tpl = $$('#order-list-tpl').html('');
// 					$$('.notData').removeClass('aui-hide');
// 		    }
// 		});
// }
</script>

</html>
